#pragma once

#include<string>
#include <thread>
#include <WinSock2.h>
#include "messageDispatcher.h"
#include "udpSender.h"
#include "loggerFactory.h"

class UdpServer : public UdpSender
{
public:
	UdpServer(MessageDispatcher<String, IPaddress>* messageDispatcher);
	~UdpServer();
	void init();
protected:
	virtual void send(UDPpacket* packet);
	virtual void send(const char* data, int len, const IPaddress& addr);
private:
	static int server_receive_thread(void* arg);
private:
	static log4cpp::Category& logger;
	SOCKET recvSocket;
	std::thread* recvThread;
	volatile int abortRequest=0;
	MessageDispatcher<String, IPaddress>* messageDispatcher;
};

